﻿@model DHQGHN.PM2.ViewModels.BangKeViewModel

@{
    ViewBag.Title = "Quản lý bảng kê";
    ViewBag.Group = "Lập bảng kê";
    Layout = "~/Views/Shared/_LayoutAdmin.cshtml";
}

<script src="~/Scripts/jquery.validate.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.js"></script>

<script>
    $(function () {
        @functions{
             public string GetAntiForgeryToken()
             {
                 string cookieToken, formToken;
                 AntiForgery.GetTokens(null, out cookieToken, out formToken);
                 return cookieToken + "," + formToken;
             }
         }
        $(document).ready(function () {
            $('#AdmUnitExtID').empty();
            var type = $('#ADM_UNIT_EXT_TYPE').val();

            if (type != "") {
                $.ajax({
                    url: '@Url.Action("ddlAdminisUnitLevel1")',
                    type: 'POST',
                    datatype: 'json',
                    headers: {
                        'VerificationToken': '@GetAntiForgeryToken()'
                    },
                    data: { parentID: "-1", type: type },
                    success: function (lstItems) {
                        $('#Level1').show();
                        if (type == "NG" || type == "NGH")
                            $('#Level1').append('<option value = "-1">' +
                                     "Đường phố" + '</option>');
                        else if (type == "DN")
                            $('#Level1').append('<option value = "-1">' +
                                     "Khu tập thể" + '</option>');
                        else if (type == "TA")
                            $('#Level1').append('<option value = "-1">' +
                                     "Khu chung cư" + '</option>');
                        else
                            $('#Level1').append('<option value = "-1">' +
                                     $('#ADM_UNIT_EXT_TYPE option:selected').text() + '</option>');

                        $.each(lstItems, function (i, lstItem) {
                            if (type == "DP" || type == "CC" || type == "TT" || type == "TO" || type == "TH" || type == "AP" || type == "BA") {
                                if (lstItem.Value == $('#AdminisUnitExtID').val())
                                    $('#Level1').append('<option value="' + lstItem.Value + '" selected="selected">' +
                                     lstItem.Text + '</option>');
                                else
                                    $('#Level1').append('<option value="' + lstItem.Value + '">' +
                                     lstItem.Text + '</option>');
                                $('#Level2').empty();
                                $('#Level2').hide();
                                $('#Level3').empty();
                                $('#Level3').hide();
                            } else if (type == "NG" || type == "DN" || type == "TA") {
                                if (lstItem.Value == $('#ParentID').val())
                                    $('#Level1').append('<option value="' + lstItem.Value + '" selected="selected">' +
                                     lstItem.Text + '</option>');
                                else
                                    $('#Level1').append('<option value="' + lstItem.Value + '">' +
                                     lstItem.Text + '</option>');
                                $('#Level3').empty();
                                $('#Level3').hide();
                            } else if (type == "NGH") {
                                if (lstItem.Value == $('#ParentID2').val())
                                    $('#Level1').append('<option value="' + lstItem.Value + '" selected="selected">' +
                                     lstItem.Text + '</option>');
                                else
                                    $('#Level1').append('<option value="' + lstItem.Value + '">' +
                                     lstItem.Text + '</option>');
                            }
                        });
                    },
                    error: function (ex) {
                        alert('Lỗi kỹ thuật.' + ex);
                    },
                    complete: function () {
                        //set selected cua Level1
                    }
                })
            };

            if ($('#Level1').val() != '-1') {
                if (type == 'NG' || type == 'TA' || type == 'DN') {
                    $.ajax({
                        url: '@Url.Action("ddlAdminisUnitLevel2")',
                        type: 'POST',
                        datatype: 'json',
                        headers: {
                            'VerificationToken': '@GetAntiForgeryToken()'
                        },
                        data: { parentID: $('#ParentID').val(), type: type },
                        success: function (lstItems) {
                            $('#Level2').show();
                            $('#Level2').append('<option value = "-1">' +
                                     $('#ADM_UNIT_EXT_TYPE option:selected').text() + '</option>');
                            $.each(lstItems, function (i, lstItem) {
                                if (lstItem.Value == $('#AdminisUnitExtID').val())
                                    $('#Level2').append('<option value="' + lstItem.Value + '" selected="selected">' +
                                     lstItem.Text + '</option>');
                                else
                                    $('#Level2').append('<option value="' + lstItem.Value + '">' +
                                     lstItem.Text + '</option>');
                                $('#Level3').empty();
                                $('#Level3').hide();
                            });
                        },
                        error: function (ex) {
                            alert('Lỗi kỹ thuật.' + ex);
                        }
                    })
                } else if (type == 'NGH') {
                    $.ajax({
                        url: '@Url.Action("ddlAdminisUnitLevel2")',
                        type: 'POST',
                        datatype: 'json',
                        headers: {
                            'VerificationToken': '@GetAntiForgeryToken()'
                        },
                        data: { parentID: $('#ParentID2').val(), type: type },
                        success: function (lstItems) {
                            $('#Level2').show();
                            $('#Level2').append('<option value = "-1">' +
                                     "Ngõ" + '</option>');

                            $.each(lstItems, function (i, lstItem) {
                                if (lstItem.Value == $('#ParentID').val())
                                    $('#Level2').append('<option value="' + lstItem.Value + '" selected="selected">' +
                                     lstItem.Text + '</option>');
                                else
                                    $('#Level2').append('<option value="' + lstItem.Value + '">' +
                                     lstItem.Text + '</option>');
                            });
                        },
                        error: function (ex) {
                            alert('Lỗi kỹ thuật.' + ex);
                        }
                    })
                }
            };


            if ($('#Level2').val() != "-1") {
                if (type == 'NGH') {
                    $.ajax({
                        url: '@Url.Action("ddlAdminisUnitLevel3")',
                        type: 'POST',
                        datatype: 'json',
                        headers: {
                            'VerificationToken': '@GetAntiForgeryToken()'
                        },
                        data: { parentID: $('#ParentID').val(), type: type },
                        success: function (lstItems) {
                            $('#Level3').show();
                            $('#Level3').append('<option value = "-1">' +
                                 $('#ADM_UNIT_EXT_TYPE option:selected').text() + '</option>');
                            $.each(lstItems, function (i, lstItem) {
                                if (type == "NGH") {
                                    if (lstItem.Value == $('#AdminisUnitExtID').val())
                                        $('#Level3').append('<option value="' + lstItem.Value + '" selected="selected">' +
                                         lstItem.Text + '</option>');
                                    else
                                        $('#Level3').append('<option value="' + lstItem.Value + '">' +
                                         lstItem.Text + '</option>');
                                }
                            });
                        },
                        error: function (ex) {
                            alert('Lỗi kỹ thuật.' + ex);
                        }
                    })
                }
            };
        });


        $('#ADM_UNIT_EXT_TYPE').change(function () {
            $('#Level1').empty();
            $('#Level2').empty();
            $('#Level3').empty();
            var type = $(this).val();
            if (type != "") {
                $.ajax({
                    url: '@Url.Action("ddlAdminisUnitLevel1")',
                    type: 'POST',
                    datatype: 'json',
                    headers: {
                        'VerificationToken': '@GetAntiForgeryToken()'
                    },
                    data: { parentID: "-1", type: type },
                    success: function (lstItems) {
                        $('#Level1').show();
                        if (type == "NGH") {
                            $('#Level1').show();
                            $('#Level2').show();
                            $('#Level3').show();
                            $('#Level1').append('<option value = "-1" selected="selected">' +
                                     "Đường phố" + '</option>');
                            $('#Level2').append('<option value = "-1" selected="selected">' +
                                     "Ngõ" + '</option>');
                            $('#Level3').append('<option value = "-1" selected="selected">' +
                                     "Ngách" + '</option>');
                        }
                        else if (type == "NG") {
                            $('#Level1').show();
                            $('#Level2').show();
                            $('#Level3').empty();
                            $('#Level3').hide();
                            $('#Level1').append('<option value = "-1" selected="selected">' +
                                     "Đường phố" + '</option>');
                            $('#Level2').append('<option value = "-1" selected="selected">' +
                                     "Ngõ" + '</option>');
                        }
                        else if (type == "DN") {
                            $('#Level1').show();
                            $('#Level2').show();
                            $('#Level3').empty();
                            $('#Level3').hide();
                            $('#Level1').append('<option value = "-1" selected="selected">' +
                                     "Khu tập thể" + '</option>');
                            $('#Level2').append('<option value = "-1" selected="selected">' +
                                     "Dãy nhà" + '</option>');
                        }
                        else if (type == "TA") {
                            $('#Level1').show();
                            $('#Level2').show();
                            $('#Level3').empty();
                            $('#Level3').hide();
                            $('#Level1').append('<option value = "-1" selected="selected">' +
                                     "Khu chung cư" + '</option>');
                            $('#Level2').append('<option value = "-1" selected="selected">' +
                                     "Tòa nhà" + '</option>');
                        }
                        else {
                            $('#Level1').show();
                            $('#Level2').empty();
                            $('#Level2').hide();
                            $('#Level3').empty();
                            $('#Level3').hide();
                            $('#Level1').append('<option value = "-1" selected="selected">' +
                                     $('#ADM_UNIT_EXT_TYPE option:selected').text() + '</option>');
                        }
                        $.each(lstItems, function (i, lstItem) {
                            $('#Level1').append('<option value="' + lstItem.Value + '">' +
                                 lstItem.Text + '</option>');
                        });
                    },
                    error: function (ex) {
                        alert('Lỗi kỹ thuật.' + ex);
                    }
                })
                return false;
            }
        });

        $('#Level1').change(function () {
            $('#Level2').empty();
            var parentID = $('#Level1').val();
            var type = $('#ADM_UNIT_EXT_TYPE').val();

            if (parentID != '-1') {
                $('#AdmUnitExtID').val($(this).val());
                if (type == 'NG' || type == 'NGH' || type == 'TA' || type == 'DN') {
                    $.ajax({
                        url: '@Url.Action("ddlAdminisUnitLevel2")',
                        type: 'POST',
                        datatype: 'json',
                        headers: {
                            'VerificationToken': '@GetAntiForgeryToken()'
                        },
                        data: { parentID: parentID, type: type },
                        success: function (lstItems) {
                            $('#Level2').show();
                            if (type == "NGH")
                                $('#Level2').append('<option value = "-1" selected="selected">' +
                                         "Ngõ" + '</option>');
                            else
                                $('#Level2').append('<option value = "-1" selected="selected">' +
                                         $('#ADM_UNIT_EXT_TYPE option:selected').text() + '</option>');
                            $.each(lstItems, function (i, lstItem) {
                                $('#Level2').append('<option value="' + lstItem.Value + '">' +
                                     lstItem.Text + '</option>');
                            });
                        },
                        error: function (ex) {
                            alert('Lỗi kỹ thuật.' + ex);
                        }
                    })
                    return false;
                }
            } else
                $('#AdmUnitExtID').empty();
        });

        $('#Level2').change(function () {
            $('#Level3').empty();

            var type = $('#ADM_UNIT_EXT_TYPE').val();
            var parentID = $(this).val();
            if (parentID != "-1") {
                $('#AdmUnitExtID').val($(this).val());
                if (type == 'NGH') {
                    $.ajax({
                        url: '@Url.Action("ddlAdminisUnitLevel3")',
                        type: 'POST',
                        datatype: 'json',
                        headers: {
                            'VerificationToken': '@GetAntiForgeryToken()'
                        },
                        data: { parentID: parentID, type: type },
                        success: function (lstItems) {
                            $('#Level3').show();
                            $('#Level3').append('<option value = "-1" selected="selected">' +
                                 $('#ADM_UNIT_EXT_TYPE option:selected').text() + '</option>');
                            $.each(lstItems, function (i, lstItem) {
                                $('#Level3').append('<option value="' + lstItem.Value + '">' +
                                     lstItem.Text + '</option>');
                            });
                        },
                        error: function (ex) {
                            alert('Lỗi kỹ thuật.' + ex);
                        }
                    })
                    return false;
                }
            } else
                $('#AdmUnitExtID').empty();
        });

        $('#Level3').change(function () {
            var parentID = $(this).val();
            if (parentID != "-1") {
                $('#AdmUnitExtID').val($(this).val());
                return false;
            } else
                $('#AdmUnitExtID').empty();
        });
    });
</script>
<div class="page-bar">
    <ul class="page-breadcrumb" style="padding: 4px;">
        <li>
            <i class="fa fa-home"></i>
            <a href="#"> Cập nhập bảng kê</a>
        </li>
    </ul>
</div>
@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

    <div class="row" style="margin-top:5px;">
        <div class="col-md-6">
            <fieldset id="fs1" class="fs_group1">
                <legend>Thông tin chung của hộ</legend>
                <div class="row" style="margin-top:5px;">
                    <div class="col-md-3">
                        @Html.LabelFor(model => model.HOUSEHOLD_NUMBER, new { @class = "text-center" })
                    </div>
                    <div class="col-md-9">
                        @Html.TextBoxFor(model => model.HOUSEHOLD_NUMBER, new { @class = "form-control  ", style = "" })
                        <span style="color: red;">@Html.ValidationMessageFor(model => model.HOUSEHOLD_NUMBER)</span>
                    </div>
                </div>
                <div class="row" style="margin-top:5px;">
                    <div class="col-md-3">
                        @Html.LabelFor(model => model.AREA_ID, new { @class = "text-center" }) <font size="3" color="red">*</font>
                    </div>
                    <div class="col-md-9 ">
                        @Html.DropDownListFor(model => model.AREA_ID, ViewBag.Area as List<SelectListItem>, "Chọn", new { @class = "form-control ", style = "  " })
                        <span style="color: red;">@Html.ValidationMessageFor(model => model.AREA_ID)</span>
                    </div>
                </div>
                <div class="row" style="margin-top:5px;">
                    <div class="col-md-3">
                        @Html.LabelFor(model => model.HOUSEHOLD_NAME, new { @class = "text-center" }) <font size="3" color="red">*</font>
                    </div>
                    <div class="col-md-9">
                        @Html.TextBoxFor(model => model.HOUSEHOLD_NAME, new { @class = "form-control  ", style = "" })
                        <span style="color: red;">@Html.ValidationMessageFor(model => model.HOUSEHOLD_NAME)</span>
                    </div>

                </div>
            </fieldset>
            <fieldset id="fs1" class="fs_group1" style="margin-top:15px;">
                <legend>Thông tin chi tiết của hộ</legend>
                <div class="row" style="margin-top:5px;">
                    <div class="col-md-3">
                        @Html.LabelFor(model => model.NUM_OF_HH_MEMBER, new { @class = "text-center" })
                    </div>
                    <div class="col-md-9">
                        @Html.TextBoxFor(model => model.NUM_OF_HH_MEMBER, new { @class = "form-control  ", style = "" })
                        <span style="color: red;">@Html.ValidationMessageFor(model => model.NUM_OF_HH_MEMBER)</span>
                    </div>
                </div>
                <div class="row" style="margin-top:5px;">
                    <div class="col-md-3">
                        @Html.LabelFor(model => model.HH_HEAD_MOBILE, new { @class = "text-center " })
                    </div>
                    <div class="col-md-9">
                        @Html.TextBoxFor(model => model.HH_HEAD_MOBILE, new { @class = "form-control  ", style = "" })
                        <span style="color: red;">@Html.ValidationMessageFor(model => model.HH_HEAD_MOBILE)</span>
                    </div>
                </div>
                <div class="row" style="margin-top:5px;">
                    <div class="col-md-3">
                        @Html.LabelFor(model => model.HH_HEAD_EMAIL, new { @class = "text-center" })
                    </div>
                    <div class="col-md-9 ">
                        @Html.TextBoxFor(model => model.HH_HEAD_EMAIL, new { @class = "form-control  ", style = "" })
                        <span style="color: red;">@Html.ValidationMessageFor(model => model.HH_HEAD_EMAIL)</span>
                    </div>
                </div>
                <div class="row" style="margin-top:5px;">
                    <div class="col-md-3">
                        @Html.LabelFor(model => model.SURVEY_METHOD_ID, new { @class = "text-center" }) <font size="3" color="red">*</font>
                    </div>
                    <div class="col-md-9">
                        @Html.DropDownListFor(model => model.SURVEY_METHOD_ID, ViewBag.SurveyMethod as List<SelectListItem>, "Chọn", new { @class = "form-control input-sm", style = " " })
                        <span style="font-size: 14px; color: red;">@Html.ValidationMessageFor(model => model.SURVEY_METHOD_ID)</span>
                    </div>
                </div>
                <div class="row" style="margin-top:5px;">
                    <div class="col-md-3 " style="vertical-align: middle;">
                        @{
                            var imgSrc = String.Format("data:image/jpeg;base64,{0}", Model.HH_HEAD_SIGNATURE);
                        }
                        @Html.LabelFor(model => model.HH_HEAD_SIGNATURE, new { @class = "text-center" })
                    </div>
                    <div class="col-md-9">
                        <img src="@imgSrc" />
                    </div>
                </div>
            </fieldset>
        </div>
        <div class="col-md-6">

            <fieldset id="fs1" class="fs_group1">
                <legend>Thông tin địa chỉ</legend>
                <div class="row" style="margin-top: 10px;">
                    <div class="col-md-3">
                        @Html.LabelFor(model => model.COUNTRY_ID, new { @class = "text-center" })
                    </div>
                    <div class="col-md-9 ">
                        Việt Nam
                    </div>
                </div>
                <div class="row" style="margin-top:5px;">
                    <div class="col-md-3">
                        @Html.LabelFor(model => model.NAME, new { @class = "text-center" }) <font size="3" color="red">*</font>
                    </div>
                    <div class="col-md-9">
                        @Html.TextBoxFor(model => model.NAME, new { @class = "form-control  ", style = " " })
                        <span style="color: red;">@Html.ValidationMessageFor(model => model.NAME)</span>
                    </div>
                </div>
                <div class="row" style="margin-top:5px;">
                    <div class="col-md-3 ">
                        @Html.LabelFor(model => model.CODE, new { @class = "text-center" })
                    </div>
                    <div class="col-md-9">
                        @Html.TextBoxFor(model => model.CODE, new { @class = "form-control  ", style = " " })
                        <span style="color: red;">@Html.ValidationMessageFor(model => model.CODE)</span>
                    </div>
                </div>
                <div class="row" style="margin-top:5px;">
                    <div class="col-md-3 ">
                        @Html.LabelFor(model => model.ADDRESS_DETAILS, new { @class = "text-center" })
                    </div>
                    <div class="col-md-9">
                        @Html.TextBoxFor(model => model.ADDRESS_DETAILS, new { @class = "form-control  ", style = " " })
                        <span style="color: red;">@Html.ValidationMessageFor(model => model.ADDRESS_DETAILS)</span>
                    </div>
                </div>

                @*</fieldset>
                    <fieldset id="fs1" class="fs_group1" style=" width: 50%;">
                        <legend>Vị trí địa lý</legend>*@
                <div class="row" style="margin-top:5px;">
                    <div class="col-md-3 ">
                        @Html.LabelFor(model => model.ADM_UNIT_EXT_TYPE, new { @class = "text-center" })
                    </div>
                    <div class="col-md-9">
                        @Html.DropDownListFor(model => model.ADM_UNIT_EXT_TYPE, ViewBag.AdminType as List<SelectListItem>, "Chọn", new { @class = "form-control", style = " " })
                        @Html.HiddenFor(model => model.ADM_UNIT_EXT_ID, new { id = "AdmUnitExtID" })
                        @Html.HiddenFor(model => model.ADM_UNIT_EXT_ID, new { id = "AdminisUnitExtID" })
                        @Html.HiddenFor(model => model.PARENT_ID, new { id = "ParentID" })
                        @Html.HiddenFor(model => model.PARENT_ID2, new { id = "ParentID2" })
                    </div>
                </div>
                <div class="row" style="margin-top:5px;">
                    <div class="col-md-3 ">
                    </div>
                    <div class="col-md-9">
                        @Html.DropDownListFor(model => model.ADM_UNIT_EXT_ID, new SelectList(string.Empty, "Value", "Text"), new { id = "Level1", style = "min-width: 29%; max-width: 29%;", @class = "" })
                        @Html.DropDownListFor(model => model.ADM_UNIT_EXT_ID, new SelectList(string.Empty, "Value", "Text"), new { id = "Level2", style = "min-width: 29%; max-width: 29%;", @class = "" })
                        @Html.DropDownListFor(model => model.ADM_UNIT_EXT_ID, new SelectList(string.Empty, "Value", "Text"), new { id = "Level3", style = "min-width: 29%; max-width: 29%;", @class = "" })
                        <span style="color: red;">@Html.ValidationMessageFor(model => model.ADM_UNIT_EXT_ID)</span>
                    </div>
                </div>
                <div class="row" style="margin-top:5px;">
                    <div class="col-md-3 ">
                        @Html.LabelFor(model => model.GPS_LONGITUDE, new { @class = "text-center" })
                    </div>
                    <div class="col-md-9">
                        @Html.TextBoxFor(model => model.GPS_LONGITUDE, new { @class = "form-control  ", style = "  " })
                        <span style="color: red;">@Html.ValidationMessageFor(model => model.GPS_LONGITUDE)</span>
                    </div>

                </div>
                <div class="row" style="margin-top:5px;">
                    <div class="col-md-3 ">
                        @Html.LabelFor(model => model.GPS_LATITUDE, new { @class = "text-center" })
                    </div>
                    <div class="col-md-9">
                        @Html.TextBoxFor(model => model.GPS_LATITUDE, new { @class = "form-control  ", style = "  " })
                        <span style="color: red;">@Html.ValidationMessageFor(model => model.GPS_LATITUDE)</span>
                    </div>
                </div>
                <div class="row" style="margin-top:5px;">
                    <div class="col-md-3 ">
                        @Html.LabelFor(model => model.GPS_ACCURACY, new { @class = "text-center" })
                    </div>
                    <div class="col-md-9">
                        @Html.TextBoxFor(model => model.GPS_ACCURACY, new { @class = "form-control  ", style = "  " })
                        <span style="color: red;">@Html.ValidationMessageFor(model => model.GPS_ACCURACY)</span>
                    </div>
                </div>
                <div class="row" style="margin-top:5px;">
                    <div class="col-md-3 " style="vertical-align: middle;">
                        @Html.LabelFor(model => model.DESCRIPTIONS, new { @class = "text-center" })
                    </div>
                    <div class="col-md-9">
                        @Html.TextAreaFor(model => model.DESCRIPTIONS, new { @class = "form-control  ", @rows = 3, style = "  " })
                        <span style="color: red;">@Html.ValidationMessageFor(model => model.DESCRIPTIONS)</span>
                    </div>
                </div>
            </fieldset>
        </div>

    </div>
    <div class="btn-hh" align="center" style="margin-top:10px;">
        <button type="submit" class="btn btn-sm btn-success" value="Lưu"><i class="fa fa-edit"></i> Sửa</button>
        <button type="button" class="btn btn-sm btn-default" value="Quay lại" onclick="window.location.href='@Url.Action("IndexHouseHoldPV")';"><i class='fa fa-reply'></i> Hủy bỏ</button>
    </div>
}
